﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace NDF.Test
{

    public class TreeNode
    {
        public int ID { get; set; }

        public string Name { get; set; }

        public override int GetHashCode()
        {
            return this.ID.GetHashCode();
        }
    }

    public class GenericEqualityComparer : EqualityComparer<TreeNode>
    {
        public override bool Equals(TreeNode x, TreeNode y)
        {
            return x.ID == y.ID;
        }

        public override int GetHashCode(TreeNode obj)
        {
            return obj.ID.GetHashCode();
        }
    }


    [TestClass]
    public class EnumerableHelperTest
    {
        public List<TreeNode> list1;
        public List<TreeNode> list2;

        public EnumerableHelperTest()
        {
            this.list1 = new List<TreeNode>();
            this.list1.Add(new TreeNode { ID = 1, Name = "Test1" });
            this.list1.Add(new TreeNode { ID = 2, Name = "Test2" });
            this.list1.Add(new TreeNode { ID = 3, Name = "Test3" });

            this.list2 = new List<TreeNode>();
            this.list2.Add(new TreeNode { ID = 1, Name = "Test11" });
            this.list2.Add(new TreeNode { ID = 2, Name = "Test12" });
            this.list2.Add(new TreeNode { ID = 13, Name = "Test13" });
            this.list2.Add(new TreeNode { ID = 14, Name = "Test14" });
            this.list2.Add(new TreeNode { ID = 15, Name = "Test15" });
        }


        [TestMethod]
        public void Except()
        {
            //var list = this.list1.Except(this.list2, (a, b) => { return a.ID == b.ID; });
            ////var list = this.list2.Except(this.list1, (a, b) => { return a.ID == b.ID; });
            ////var list = this.list1.Except(this.list2, (a, b) => { return a.ID == b.ID; }, a => a.ID.GetHashCode());
            ////var list = this.list1.Except(this.list2, new GenericEqualityComparer());
            ////var list = this.list1.Except(this.list2, new NDF.GenericEqualityComparer<TreeNode>((a, b) => { return a.ID == b.ID; }));

            //foreach (var item in list)
            //{
            //    Console.WriteLine(item.ID + ":" + item.Name);
            //}
        }


        [TestMethod]
        public void GenericTest()
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            List<string> list = new List<string>();
            ArrayList array = new ArrayList();
            IEnumerable e1 = array;
            IEnumerable<string> e2 = list;


        }
    }
}
